<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>我的订单</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand" />
    <link rel="shortcut icon" href="/favicon.ico" type="/image/x-icon">
    <link rel="apple-touch-icon-precomposed" href="">
    <link rel="stylesheet" href="../source/src/css/main.css"/>
    
</head>
<body class="my-order-body">
<!-- 我的订单 -->
<div class="my-order">
    <div class="order-list">
        <ul class="order-list-ul clearfix" id="order-list-ul">
            <!--<li class="order-detail">
                <div class="hd">
                    <span class="check-all">
                        <input type="checkbox" id="checkbox-2-1" class="beautify-checkbox" />
                        <label for="checkbox-2-1"></label>
                    </span>
                    <span class="order-num">
                        订单号：23435415656
                    </span>
                    <span class="audit-state">
                        未审核
                    </span>

                    <a href="javascript:;" class="delete fr" title="删除"></a>
                </div>
                <div class="bd">
                    <div class="order-item clearfix diy-box">
                        <div class="check-state">
                            <div class="ico">
                                <input type="checkbox" id="checkbox-1-2" class="beautify-checkbox" />
                                <label for="checkbox-1-2"></label>
                            </div>
                        </div>
                        <div class="pro-inro flex-1 clearfix">
                            <div class="pic fl">
                                <img src="../source/img/shop_list/product.jpg" alt="">
                            </div>
                            <div class="txt fl">
                                <h2>洗精液</h2>
                                <div class="other">
                                    规格：20ML
                                </div>
                            </div>
                        </div>
                        <div class="num-box">
                            x 1
                        </div>
                    </div>
                    <div class="order-item clearfix diy-box">
                        <div class="check-state">
                            <div class="ico">
                                <input type="checkbox" id="checkbox-1-3" class="beautify-checkbox" />
                                <label for="checkbox-1-3"></label>
                            </div>
                        </div>
                        <div class="pro-inro flex-1 clearfix">
                            <div class="pic fl">
                                <img src="../source/img/shop_list/product.jpg" alt="">
                            </div>
                            <div class="txt fl">
                                <h2>洗精液</h2>
                                <div class="other">
                                    规格：20ML
                                </div>
                            </div>
                        </div>
                        <div class="num-box">
                            x 3
                        </div>
                    </div>
                </div>
                <div class="ft clearfix">
                    <span class="order-time fl">
                        订单日期：2016-11-01
                    </span>
                    <a href="javascript:;" class="buy-agin-btn fr">
                        再次购买
                    </a>
                </div>
            </li>-->
        </ul>
    </div>
</div>

<!--底部菜单-->
<div class="pub-nav">
    <ul>
        <li>
            <a href="../index.html">
                <div class="index pic"></div>
                <div class="txt">首页</div>
            </a>
        </li>
        <li>
            <a href="./shop_cart.html">
                <div class="shopCart pic"></div>
                <div class="txt">购物车</div>
            </a>
        </li>
        <li class="on">
            <a href="./me.html">
                <div class="me pic"></div>
                <div class="txt">我</div>
            </a>
        </li>
    </ul>
</div>
<!--/底部菜单-->

<script id="order-list-ul-tpl" type="text/html">
    {{each OrderLists as li i}}
    <li class="order-detail">
        <div class="hd">
           <!-- <span class="check-all">
                <input type="checkbox" id="checkbox-1-{{i}}" class="beautify-checkbox" />
                <label for="checkbox-1-{{i}}"></label>
            </span>-->
            <span class="order-num">
                订单号：{{li.BillNo}}
            </span>
            <span class="audit-state">
                {{if li.State == 0}}
                未审核
                {{/if}}
                {{if li.State !=0}}
                已审核
                {{/if}}
            </span>

            <a href="javascript:;" class="delete fr" title="删除" data-billNo="{{li.BillNo}}"></a>
        </div>
        <div class="bd">
            {{each li.ItemList as item k}}
            <div class="order-item clearfix diy-box">
                <!--<div class="check-state">
                    <div class="ico">
                        <input type="checkbox" id="checkbox-2-{{k}}" class="beautify-checkbox" />
                        <label for="checkbox-2-{{k}}"></label>
                    </div>
                </div>-->
                <div class="pro-inro flex-1 clearfix">
                    <div class="pic fl">
                        <img src="{{item.Picture}}" alt="{{item.Name}}">
                    </div>
                    <div class="txt fl">
                        <h2>{{item.Name}}</h2>
                        <div class="other">
                            规格：{{item.Model}}
                        </div>
                    </div>
                </div>
                <div class="num-box">
                    x {{item.Qty}}
                </div>
            </div>
            {{/each}}
        </div>
        <div class="ft clearfix">
            <span class="order-time fl">
                订单日期：{{li.Date}}
            </span>
            <a href="javascript:;" class="buy-agin-btn fr" data-billNo="{{li.BillNo}}">
                再次购买
            </a>
        </div>
    </li>
    {{/each}}
</script>

    <!-- /订单信息 -->
    <script src="../source/plugin/zepto.min.js"></script>
    <script src="../source/plugin/artTemplate.js"></script>
    <script src="../source/src/js/common.js"></script>
    <script>
        var init={
            render:function(){
                //render渲染
                var inJson = {
                    "custcode":getCookie('CustCode'),
                    "empcode":getCookie('EmpCode'),
                    "type":getCookie('Type'),
                    "pageindex":1,
                    "pagecount":5,
                    "key":user.key,
                    "account":user.account
                };

                $.ajax({
                    url:apiUrl+'/GetOrderItems',
                    type:'GET',
                    data:{"json":JSON.stringify(inJson)},
                    //          dataType :'jsonp',
                    success:function(datas){
                        console.log(datas);
                        var html = template('order-list-ul-tpl', datas);
                        $('#order-list-ul').html(html);
                    },
                    error:function(datas){
                        console.log(datas)
                    }
                });
            },
            checkAll:function(){
                $('.check-all').on('click',function(){
                    var $this = $(this);
                    checkbox = $this.find('input[type=checkbox]');
                    if(checkbox.prop('checked')){
                        $this.parents('.order-detail').find('input[type=checkbox]').prop('checked',true);
                    }else{
                        $this.parents('.order-detail').find('input[type=checkbox]').prop('checked',false);
                    }
                });
            },
            buyAgainByOrder:function(){
                $('#order-list-ul').on('click','.buy-agin-btn',function(){
                    var inJson = {
                        "BillNo":$(this).attr('data-billNo'),
                        "username":decodeURIComponent(getCookie('username')),
                        "key":user.key,
                        "account":user.account
                    };

                    $.ajax({
                        url:apiUrl+'/GetOrderItemBuy',
                        type:'GET',
                        data:{"json":JSON.stringify(inJson)},
                        //          dataType :'jsonp',
                        success:function(datas){
                            if(datas.Success==true){
                                show_error_tip({str:"再次购买成功"});
                                location.href="shop_cart.html";
                            }
                            /*datas.OrderLists[0].UserName=getCookie('username');
                            datas.OrderLists[0].key=user.key;
                            datas.OrderLists[0].account=user.account;

                            console.log(datas)


                            $.ajax({
                                url:apiUrl+'/SubmitCarItems',
                                type:'GET',
                                data:{"json":JSON.stringify(datas)},
                                //          dataType :'jsonp',
                                success:function(datas){
                                    show_error_tip({str:"再次购买成功"});
                                },
                                error:function(datas){
                                    console.log(datas.msg)
                                }
                            });*/
                        },
                        error:function(datas){
                            console.log(datas)
                        }
                    });
                });
            },
            deleteOrder:function(){
                $('#order-list-ul').on('click','.delete',function(){
                    var $this = $(this);
                    var inJson = {
                        "BillNo":$this.attr('data-billNo'),
                        "key":user.key,
                        "account":user.account
                    };

                    $.ajax({
                        url:apiUrl+'/DeleteOrder',
                        type:'GET',
                        data:{"json":JSON.stringify(inJson)},
                        //          dataType :'jsonp',
                        success:function(datas){
                            if(datas.Success==true){
                                $this.parents('li').remove();
                                show_error_tip({str:"订单删除成功"});
                            }else{
                                show_error_tip({str:"订单删除失败"});
                            }
                        },
                        error:function(datas){
                            console.log(datas.msg)
                        }
                    });
                });
            },
            showMorePage:function(){
                window.onload=function(aaa){
                    var scrollTimer = null;
                    var listUl = $('#list-ul');
                    $(window).scroll(function(){
                        clearTimeout(scrollTimer);
                        function showMore(){
                            if($('body,html').height() - $(window).scrollTop() -$(window).height() <= 160){
                                var currentPage = listUl.attr('data-page');
                                var totalPage = Math.ceil(1000/6);
                                currentPage++;
                                if(currentPage<=totalPage){
                                    var inJson = {
                                        "custcode":getCookie('CustCode'),
                                        "empcode":getCookie('EmpCode'),
                                        "pageindex":currentPage,
                                        "pagecount":5,
                                        "key":user.key,
                                        "account":user.account
                                    };

                                    $.ajax({
                                        url:apiUrl+'/GetOrderItems',
                                        type:'GET',
                                        data:{"json":JSON.stringify(inJson)},
                                        //          dataType :'jsonp',
                                        success:function(datas){
                                            console.log(datas);
                                            var html = template('order-list-ul-tpl', datas);
                                            $('#order-list-ul').append(html);
                                        },
                                        error:function(datas){
                                            console.log(datas)
                                        }
                                    });
                                }else{
                                    return false;
                                }
                            }
                        }

                        scrollTimer = setTimeout(function(){
                            showMore();
                        },200)
                    });
                }
            },
            init:function(){
                this.render();
                this.deleteOrder();
                this.checkAll();
                this.buyAgainByOrder();
                this.deleteOrder();
                this.showMorePage();
            }
        };
        init.init();
    </script>
</body>
</html>